package com.example.demo.entity;

import java.util.List;
import org.babyfish.jimmer.sql.Column;
import org.babyfish.jimmer.sql.Entity;
import org.babyfish.jimmer.sql.GeneratedValue;
import org.babyfish.jimmer.sql.GenerationType;
import org.babyfish.jimmer.sql.Id;
import org.babyfish.jimmer.sql.JoinColumn;
import org.babyfish.jimmer.sql.ManyToOne;
import org.babyfish.jimmer.sql.OneToMany;
import org.babyfish.jimmer.sql.Table;
import org.jetbrains.annotations.Nullable;

/**
 * 菜单项
 *
 * @author jimmer
 * @since 2024-02-03 02:20:59
 */
@Entity
@Table(name = "menu")
public interface Menu {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    long id();

    /**
     * 父级菜单项
     */
    @ManyToOne
    @JoinColumn(
            name = "parent_id",
            referencedColumnName = "id"
    )
    @Nullable
    Menu parent();

    /**
     * 子级菜单项
     */
    @OneToMany(mappedBy = "parent")
    List<Menu> children();

    /**
     * 资源
     */
    @OneToMany(mappedBy = "menu")
    List<Resource> resources();

    /**
     * 名称
     */
    @Column(name = "name")
    String name();
}
